package com.jming.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jming.yygh.common.result.Result;
import com.jming.yygh.model.user.UserInfo;
import com.jming.yygh.user.service.UserInfoService;
import com.jming.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author jming
 * @version 0.0.1
 * @date 2021/05/13
 */

@Api(tags = "用户管理接口")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;

    /**
     * 条件查询带分页的用户列表
     * @param page
     * @param limit
     * @param userInfoQueryVo
     * @return Result
     */
    @ApiOperation(value = "条件查询带分页的用户列表")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo) {

        Page<UserInfo> pageparam = new Page<>(page, limit);

        IPage<UserInfo> pageModel = userInfoService.selectPage(pageparam, userInfoQueryVo);

        return Result.ok(pageModel);

    }

    /**
     * 锁定用户
     * @param userId
     * @param status
     * @return Result
     */
    @ApiOperation(value = "锁定用户")
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable Long userId,
                       @PathVariable Integer status) {

        userInfoService.lock(userId, status);

        return Result.ok();
    }

    /**
     * 根据用户id查看用户详情信息
     * @param userId
     * @return Result
     */
    @ApiOperation(value = "根据用户id查看用户详情信息")
    @GetMapping("show/{userId}")
    public Result show(@PathVariable Long userId) {

        Map<String, Object> map = userInfoService.show(userId);

        return Result.ok(map);

    }

    /**
     * 用户审批列表
     * @param userId
     * @param authStatus
     * @return Result
     */
    @ApiOperation(value = "用户审批列表")
    @GetMapping("approvar/{userId}/{authStatus}")
    public Result approvar(@PathVariable Long userId,
                           @PathVariable Integer authStatus) {

        userInfoService.approvar(userId, authStatus);

        return Result.ok();
    }

}
